/*
 * @Date: 2023-03-08 16:22:05
 * @LastEditors: Zireael 1193875164@qq.com
 * @LastEditTime: 2023-03-08 16:32:36
 * @FilePath: \A19\backend\src\api\QuestionsSys\ApiEditQuestion.ts
 */
import { ApiCall } from "tsrpc";
import { ReqEditQuestion, ResEditQuestion } from "../../shared/protocols/QuestionsSys/PtlEditQuestion";
import { Global } from '../../Global/index';

export default async function (call: ApiCall<ReqEditQuestion, ResEditQuestion>) {
    
    // const questionInDB = await Global.collection('questions').findOne({
    //     _id:call.req._id
    // })

    // if(!questionInDB) return call.error('本题不存在')

   await Global.collection('questions').updateOne({
        _id:call.req._id
    },{
        $set:{
            question:call.req.question,
            answer:call.req.answer
        }
    })
    
    const q = await Global.collection('questions').findOne({
        _id:call.req._id
    })
    if(!q) return call.error('本题不存在')

    call.succ({
        question:q
    })

}